package com.ourcraft.informationcollectionsystem.utils;

import com.alibaba.fastjson.JSONObject;

public class LowerCamelToLowerUnderscore {
    public static String exec(String str){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < str.length(); i++){
            char c = str.charAt(i);
            if(Character.isUpperCase(c)){
                sb.append("_");
                sb.append(Character.toLowerCase(c));
            }else{
                sb.append(c);
            }
        }
        return sb.toString();
    }

    public static JSONObject exec_json(JSONObject j){
        JSONObject new_j = new JSONObject();
        if (j != null){
            for(String key : j.keySet()) {
                String new_key = exec(key);
                new_j.put(new_key, j.get(key));
            }
        }
        return new_j;
    }
}
